<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
  <title>区块链推广管理中心</title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
  <link href="http://cmanage.shinechain.io/vendor/css/bootstrap.min.css" rel="stylesheet" />
  <link href='http://cmanage.shinechain.io/build/css/style.min.css' rel='stylesheet' type='text/css'>
  <link href="http://cmanage.shinechain.io/build/css/material-dashboard.min.css" rel="stylesheet" />
  <script src="http://cmanage.shinechain.io/vendor/js/jquery-3.1.0.min.js" type="text/javascript"></script>
</head>
<style>
  body{
    background: #ffffff;
  }
  .main{
    width: 90%;
    margin: 0 auto;
  }
  .main>.title{
    text-align: center;
    margin-top: 5%;
  }
  #template{
    display: none;
  }
  .block {
    display: inline-block;
    width: 30.1%;
    border: 1px solid #d9d9d9;
    margin: 50px 1.5% 0 1.5%;
  }

  .block>.title {
    font-size: 25px;
    line-height: 100px;
    height: 100px;
    text-align: center;
    font-weight: bold;
  }

  .block .ctrl {
    text-align: right;
    display: inline-block;
    float: right;
    height: 100%;
  }

  .block .weui_switch {
    vertical-align: middle;
  }

  .block>.title>input {
    display: inline-block;
    float: right;
    margin-top: 35px;
  }

  .block>.body {
    text-align: center;
  }

  .block>.body p {
    height: 42px;
    display: none;
    position: relative;
    margin-left: auto;
    margin-right: auto;
    padding-left: 14px;
    padding-right: 14px;
    box-sizing: border-box;
    font-size: 14px;
    text-decoration: none;
    line-height: 2.33333333;
    border-radius: 5px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    overflow: hidden;
    text-align: left;
  }
</style>

<body>
    <div class='main'>
    	<h2 align="middle">闪链电报机器人管理中心</h2>
      <div id='template' class='block'>
        <div class='title'>{{name}}
          <div class="ctrl">
            <input class="weui_switch" type="checkbox" {{checked}} data-slug='{{slug}}'>
          </div>
        </div>
        <div class='body'>
          <a href="{{url}}" class="weui_btn weui_btn_default">设置</a>
          <p>功能介绍:{{description}}</p>
        </div>
      </div>
    </div>

<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
    $(function() {
        var options = [{
            'name': '入群欢迎语',
            'url': '/pages/welcome.html',
            'checked': '',
            'slug': 'useWelcome',
            'description': '有人进群时机器人自动发送话语'
        }, {
            'name': '自动踢人',
            'url': '/pages/autoeliminate.html',
            'checked': '',
            'slug': 'useKitMan',
            'description': '根据条件自动踢人'
        }, {
            'name': '自动删除消息',
            'url': '/pages/autodeletemsg.html',
            'checked': '',
            'slug': 'useDeleteMsg',
            'description': '根据条件选择删除信息'
        }, {
            'name': '关键词自动回复',
            'url': '/pages/autoreply.html',
            'checked': '',
            'slug': 'useChat',
            'description': '传入excel表格即可开启'
        }, {
            'name': '抢红包送Token',
            'url': '/pages/redpaper.html',
            'checked': '',
            'slug': 'useRedPaper',
            'description': '可以在此发送红包'
        }, {
            'name': '竞猜小游戏',
            'url': '/pages/game.html',
            'checked': '',
            'slug': 'useGuessing',
            'description': '发送竞猜小游戏'
        }, {
            'name': '定时发送消息',
            'url': '/pages/msgtimer.html',
            'checked': '',
            'slug': 'useSendMsgOnTime',
            'description': '配置好即可定时发信息'
        }, {
            'name': '邀请用户入群送Token',
            'url': '/pages/sendtoken.html',
            'checked': '',
            'slug': 'useToken',
            'description': '可设定奖励规则'
        }, {
            'name': '机器人聊天',
            'url': '',
            'checked': '',
            'slug': 'useTuling',
            'description': '@机器人自动聊天'
        }, {
            'name': '阻止非管理员添加机器人',
            'url': '',
            'checked': '',
            'slug': 'disableAddBot',
            'description': '防止机器人骚扰'
        }, {
            'name': '签到送Token',
            'url': '/pages/checkIn.html',
            'checked': '',
            'slug': 'useCheckIn',
            'description': '定制签到送多少token'
        }, {
            'name': '聊天送Token',
            'url': '/pages/chatToken.html',
            'checked': '',
            'slug': 'useChatToken',
            'description': '每天聊天送token(提升群活跃度)'
        }];

        var setButton = function() {
            $('.block').each(function() {
                if(!$(this).find('.title input').is(":checked")) {
                    $(this).find('.body a').hide();
                    $(this).find('.body p').show();
                } else {
                    $(this).find('.body a').show();
                    $(this).find('.body p').hide();
                }
                if($(this).find('.body a').attr('href') == '') {
                    $(this).find('.body a').hide();
                    $(this).find('.body p').show();
                }
            })
        }


        var ip = 'http://bot.shinechain.io';
        var clickThing = function (){
            $('.weui_switch').click(function() {
                var slug = $(this).data('slug');
                var checked = $(this).is(":checked");
                var self = $(this);
                /*
                if(result == true) {
                  window.alert("true");
                  self.prop("checked", 'checked');
                } else {
                  self.prop("checked", '');
                  window.alert('false');
                }
                setButton();
                */
                /*

                */
                $.get(ip+'/botApi/botMethod?botMethod='+slug, function(result){
                    if (result && result.status == 200){
                        if(result.botMethod == true){
                            self.prop("checked",true);
                        }else{
                            self.prop("checked",false);
                        }
                        setButton();
                    }else {
                        window.alert(result.errorMsg);
                    }
                });
            });
        }
        var getInfo = function () {

            $.get(ip + '/botApi/getAll', function(res) {
                options.map(function(value, index) {
                    var slug = value.slug;
                    if(res.botMethod[slug] == true) {
                        options[index]['checked'] = 'checked';
                    }
                });
                /*
                  res.botMethod.map(function(value, index){
                    options[index]['checked'] = (value == false ? '' : 'checked');
                  });*/

                options.map(function(value) {
                    var html = $('#template').clone().attr('id', '').prop("outerHTML");
                    for(var index in value) {
                        html = html.replace("{{" + index + "}}", value[index]);
                    }
                    $('.main').append(html);
                });
                setButton();
                clickThing();
            })
        };

        getInfo();
    });
</script>
</body>

</html>